from info.modules.home import home_blu
from info import rs
import logging
from flask import current_app, render_template


# 首页
@home_blu.route('/')
def index():
    # logging.error("出现了一个错误")
    # current_app.logger.error("出现了一个错误")
    # return "index"
    return render_template("index.html")


# 第二步，使用蓝图对象注册路由

"""
# 注册页面
@home_blu.route('/register')
def register():
    return render_template("register.html")


@home_blu.route('/register_submit')
def register_submit():
    # 接收参数
    userName = request.args.get("userName")
    pwd = request.args.get("pwd")
    pwd2 = request.args.get("pwd2")
    print(userName)
    print(pwd)
    print(pwd2)
    # 校验参数
    if not all([userName, pwd, pwd2]):
        return "参数不足"
    if pwd != pwd2:
        return "两次密码输入不一致"

    db.drop_all()
    db.create_all()

    user = User()
    user.name = userName
    user.pwd = pwd

    db.session.add(user)
    db.session.commit()
    return "注册成功"


# 登录页面
@home_blu.route('/login')
def login():
    return render_template("login.html")


@home_blu.route('/login_submit')
def login_submit():
    # 接受参数
    lg_username = request.args.get("username")
    lg_passward = request.args.get("password")
    print(lg_username)
    print(lg_passward)
    # 校验参数
    if not all([lg_passward, lg_username]):
        return "参数不足"

    user = User.query.filter_by(name=lg_username).first()
    print(user.pwd)
    if user:
        if user.pwd == lg_passward:
            return "登录成功"
        else:
            return "登录失败，请重新输入"
    return "用户不存在，请注册"
"""
